package design;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Li_yizYa
 * Date: 2025/8/29
 * Time: 20:57
 */
// 产品接口
interface Phone{
    void make();
}
// 具体产品
class Iphone implements Phone{
    @Override
    public void make() {
        System.out.println("生产一部苹果手机");
    }
}
// 具体产品
class HuaWeiPhone implements Phone {
    @Override
    public void make() {
        System.out.println("生产一部华为手机");
    }
}
// 工厂接口
interface PhoneFactory{
    Phone createPhone(); // 工厂方法
}
//具体工厂
class IPhoneFactory implements PhoneFactory {
    @Override
    public Phone createPhone() {
        return new Iphone();
    }
}

//具体工厂
class HuaweiPhoneFactory implements PhoneFactory {
    @Override
    public Phone createPhone() {
        return new HuaWeiPhone();
    }
}
public class FactoryPatternDemo {
    public static void main(String[] args) {
        // 想要iphone就找，iphone工厂
        PhoneFactory iphoneFactory = new IPhoneFactory();
        Phone iphone = iphoneFactory.createPhone();
        iphone.make();
        // 想要huawei，就找huawei工厂
        PhoneFactory huaweiPhoneFactory = new HuaweiPhoneFactory();
        Phone huawei = huaweiPhoneFactory.createPhone();
        huawei.make();
    }
}
